package server.datamodel;


public class Tile {

	private String ID;
	private CreepSmashGame game;
	private String position;
	private UserAssets userAssets;
	private Map map;
//	private User user;
	
	public Tile() {
		this.ID = Datamodel.generateID(this);
	}
	
	@Override
	public String toString() {
		return ID;
	}
	
	public String getID() {
		return ID;
	}
	
	public void setID(String iD) {
		ID = iD;
	}

	public CreepSmashGame getGame() {
		return game;
	}

	public String getPosition() {
		return position;
	}
	
	public void setPosition(String position) {
		this.position = position;
	}
	
	public UserAssets getUserAssets() {
		return userAssets;
	}
	
	public void setGame(CreepSmashGame game) {
		if(this.game != game) {
			if(getGame() != null) {
				getGame().removeTile(this);
			}
			this.game = game;
			if(getGame() != null) {
				getGame().addTile(this);
			}
		}
	}
	
	public void setMap(Map map) {
		if(this.map != map) {
			if(getMap() != null) {
				Map oldMap = getMap();
				this.map = null;
				oldMap.setTile(null);
			}
			this.map = map;
			if(getMap() != null) {
				getMap().setTile(this);
			}
		}
	}
	
	public void setUserAssets(UserAssets userAssets) {
		if(this.userAssets != userAssets) {
			getGame().broadcast(this, "userAssets", this.userAssets, userAssets);
			
			if(getUserAssets() != null) {
				UserAssets oldUserAssets = getUserAssets();
				this.userAssets = null;
				oldUserAssets.setTile(null);
			}
			this.userAssets = userAssets;
			if(getUserAssets() != null) {
				getUserAssets().setTile(this);
			}
		}
	}
	
//	public void setUser(User user) {
//		if(this.user != user) {
//			if(getUser() != null) {
//				User oldUser = getUser();
//				this.user = null;
//				oldUser.setTile(null);
//			}
//			this.user = user;
//			if(getUser() != null) {
//				getUser().setTile(this);
//			}
//		}
//	}
	
//	public User getUser() {
//		return user;
//	}
	
	public Map getMap() {
		return map;
	}
	
	
}
